from os.path import exists nam=input("Enter name of file: ") f=open(nam,'w') st=input("Enter your text: ") f.write(st) f.close() if(exists("Amit.txt")): print("File present") else: print("file not present")